package jmvm.schemes;


import java.awt.Point;
import java.util.ArrayList;

import jmvm.components.*;
import jmvm.gui.GuiLabel;
import jmvm.gui.GuiLine;
import jmvm.gui.GuiScheme;


public class Exec1 {

	public static IntToInt AB_zero_extend, AW_H;
	public static IntToBools ABBits, BBBits, ALUBits;
	
	public static CD CD1, CD2;
	public static MP MX3, MX4;
	public static REG AB, BB, AW, BW;
	public static ALU ALUExec;
	
	public static TSB ABout, ALUout, BBout, AWHout, AWout, BWout;
	
	////////////
	//////////// Grafika
	////////////
	
	public static GuiScheme gui;

	public static GuiScheme getGui() {
		return gui;
	}
	
	public static void gui() {

		GuiLine line; // Pomocna promenljiva
		gui = new GuiScheme("jmvm/jmvm/images/exec1.png");
		
		ArrayList<ArrayList<Point>> sections;
		ArrayList<Point> points;
		
		// 
		// 
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(318,36));
		points.add(new Point(411,36));
		sections.add(points);
		line=new GuiLine(sections,AB_zero_extend.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(435,36));
		points.add(new Point(512,36));
		sections.add(points);
		line=new GuiLine(sections,ABout.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(512,2));
		points.add(new Point(512,763));
		points.add(new Point(514,763));
		points.add(new Point(514,2));
		sections.add(points);
		line=new GuiLine(sections,Bus.IBUS());
		gui.addLine(line);
		
		// 
		// 
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(228,113));
		points.add(new Point(228,84));
		points.add(new Point(409,84));
		sections.add(points);
		line=new GuiLine(sections,ALUExec.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(433,84));
		points.add(new Point(512,84));
		sections.add(points);
		line=new GuiLine(sections,ALUout.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(285,114));
		points.add(new Point(285,99));
		points.add(new Point(308,99));
		sections.add(points);
		line=new GuiLine(sections,ALUExec.getPinC8());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(153,210));
		points.add(new Point(171,210));
		points.add(new Point(171,200));
		sections.add(points);
		line=new GuiLine(sections,new Pin(false));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(117,266));
		points.add(new Point(117,223));
		points.add(new Point(193,223));
		points.add(new Point(193,200));
		sections.add(points);
		line=new GuiLine(sections,AB.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(338,266));
		points.add(new Point(338,224));
		points.add(new Point(263,223));
		points.add(new Point(263,200));
		sections.add(points);
		line=new GuiLine(sections,BB.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(339,223));
		points.add(new Point(409,223));
		sections.add(points);
		line=new GuiLine(sections,BB.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(433,223));
		points.add(new Point(512,223));
		sections.add(points);
		line=new GuiLine(sections,BBout.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(117,310));
		points.add(new Point(117,329));
		points.add(new Point(512,329));
		sections.add(points);
		line=new GuiLine(sections,Bus.IBUS());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(338,327));
		points.add(new Point(338,310));
		sections.add(points);
		line=new GuiLine(sections,Bus.IBUS());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(312,414));
		points.add(new Point(329,414));
		points.add(new Point(329,347));
		points.add(new Point(198,347));
		points.add(new Point(198,300));
		points.add(new Point(192,300));
		sections.add(points);
		line=new GuiLine(sections,MX4.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(146,414));
		points.add(new Point(162,414));
		points.add(new Point(162,348));
		points.add(new Point(36,348));
		points.add(new Point(36,301));
		points.add(new Point(43,301));
		sections.add(points);
		line=new GuiLine(sections,MX3.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(146,529));
		points.add(new Point(154,529));
		points.add(new Point(154,481));
		points.add(new Point(108,481));
		points.add(new Point(108,463));
		sections.add(points);
		line=new GuiLine(sections,CD1.getOut(1));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(146,548));
		points.add(new Point(163,548));
		points.add(new Point(163,472));
		points.add(new Point(127,472));
		points.add(new Point(127,463));
		sections.add(points);
		line=new GuiLine(sections,CD1.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(312,529));
		points.add(new Point(320,529));
		points.add(new Point(320,481));
		points.add(new Point(274,481));
		points.add(new Point(274,463));
		sections.add(points);
		line=new GuiLine(sections,CD2.getOut(1));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(312,548));
		points.add(new Point(329,548));
		points.add(new Point(329,471));
		points.add(new Point(292,471));
		points.add(new Point(292,463));
		sections.add(points);
		line=new GuiLine(sections,CD2.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(347,569));
		points.add(new Point(411,569));
		sections.add(points);
		line=new GuiLine(sections,AW.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(366,568));
		points.add(new Point(366,521));
		points.add(new Point(411,521));
		sections.add(points);
		line=new GuiLine(sections,AW_H.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(435,521));
		points.add(new Point(512,521));
		sections.add(points);
		line=new GuiLine(sections,AWHout.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(434,569));
		points.add(new Point(512,569));
		sections.add(points);
		line=new GuiLine(sections,AWout.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(366,667));
		points.add(new Point(366,617));
		points.add(new Point(411,617));
		sections.add(points);
		line=new GuiLine(sections,BW.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(434,617));
		points.add(new Point(512,617));
		sections.add(points);
		line=new GuiLine(sections,BWout.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(512,729));
		points.add(new Point(145,729));
		points.add(new Point(145,712));
		sections.add(points);
		line=new GuiLine(sections,Bus.IBUS());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(366,728));
		points.add(new Point(366,711));
		sections.add(points);
		line=new GuiLine(sections,Bus.IBUS());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(145,667));
		points.add(new Point(145,649));
		sections.add(points);
		line=new GuiLine(sections,AW.getOut(0));
		gui.addLine(line);

		//
		//
		// 
		// 
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(423,48));
		points.add(new Point(423,42));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.ABout());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(421,95));
		points.add(new Point(421,89));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.ALUout());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(149,133));
		points.add(new Point(155,133));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.not());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(150,149));
		points.add(new Point(155,149));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.xor());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(149,164));
		points.add(new Point(155,164));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.or());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(149,179));
		points.add(new Point(155,179));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.and());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(301,133));
		points.add(new Point(307,133));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.dec());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(301,149));
		points.add(new Point(307,149));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.inc());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(301,164));
		points.add(new Point(307,164));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.sub());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(301,179));
		points.add(new Point(307,179));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.add());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(421,235));
		points.add(new Point(421,230));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.BBout());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(37,288));
		points.add(new Point(43,288));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.shr());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(192,277));
		points.add(new Point(198,277));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.ldAB());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(192,288));
		points.add(new Point(198,288));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.shl());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(413,288));
		points.add(new Point(420,288));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.ldBB());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(83,386));
		points.add(new Point(89,386));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWC());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(82,405));
		points.add(new Point(89,405));
		sections.add(points);
		line=new GuiLine(sections,ABBits.getOut(0));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(82,424));
		points.add(new Point(89,424));
		sections.add(points);
		line=new GuiLine(sections,new Pin(false));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(82,443));
		points.add(new Point(89,443));
		sections.add(points);
		line=new GuiLine(sections,ABBits.getOut(7));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(248,386));
		points.add(new Point(254,386));
		sections.add(points);
		line=new GuiLine(sections,Exec2.PSWC());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(248,405));
		points.add(new Point(255,405));
		sections.add(points);
		line=new GuiLine(sections,ABBits.getOut(7));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(248,424));
		points.add(new Point(254,424));
		sections.add(points);
		line=new GuiLine(sections,new Pin(false));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(248,443));
		points.add(new Point(254,443));
		sections.add(points);
		line=new GuiLine(sections,new Pin(false));
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(82,510));
		points.add(new Point(89,510));
		sections.add(points);
		line=new GuiLine(sections,Fetch2.RORC());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(82,529));
		points.add(new Point(89,529));
		sections.add(points);
		line=new GuiLine(sections,Fetch2.ROR());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(83,548));
		points.add(new Point(89,548));
		sections.add(points);
		line=new GuiLine(sections,Fetch2.LSR());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(82,567));
		points.add(new Point(89,567));
		sections.add(points);
		line=new GuiLine(sections,Fetch2.ASR());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(248,510));
		points.add(new Point(254,510));
		sections.add(points);
		line=new GuiLine(sections,Fetch2.ROLC());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(249,529));
		points.add(new Point(254,529));
		sections.add(points);
		line=new GuiLine(sections,Fetch2.ROL());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(248,548));
		points.add(new Point(254,548));
		sections.add(points);
		line=new GuiLine(sections,Fetch2.LSL());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(248,567));
		points.add(new Point(254,567));
		sections.add(points);
		line=new GuiLine(sections,Fetch2.ASL());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(423,533));
		points.add(new Point(423,527));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.AWHout());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(423,580));
		points.add(new Point(423,575));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.AWout());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(423,628));
		points.add(new Point(423,623));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.BWout());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(64,689));
		points.add(new Point(70,689));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.ldAW());
		gui.addLine(line);

		//
		//
		sections=new ArrayList<ArrayList<Point>>();
		points=new ArrayList<Point>();
		points.add(new Point(285,689));
		points.add(new Point(291,689));
		sections.add(points);
		line=new GuiLine(sections,UpravOper.ldBW());
		gui.addLine(line);

		//
		//
		gui.addLabel(new GuiLabel(522, 140, Bus.IBUS()));
		gui.addLabel(new GuiLabel(222, 82, ALUExec.getOut(0)));
		gui.addLabel(new GuiLabel(113, 221, AB.getOut(0)));
		gui.addLabel(new GuiLabel(336, 220, BB.getOut(0)));
		gui.addLabel(new GuiLabel(143, 643, AW.getOut(0)));
		gui.addLabel(new GuiLabel(363, 614, BW.getOut(0)));


	}
	
	

	//
	//

	/////////////
	/////////////
	/////////////
	
	public static void init() {
		
		////
		AB_zero_extend = new IntToInt(8,16,false,false); 
		AW_H = new IntToInt(16,8,true,false);
		ABBits = new IntToBools(8,8);
		BBBits = new IntToBools(8,8);
		ALUBits = new IntToBools(8,8);
		////
		
		CD1 = new CD(4);
		CD1.setE(new Pin(true));
		
		CD2 = new CD(4);
		CD2.setE(new Pin(true));
		
		MX3 = new MP(4);
		
		MX4 = new MP(4);
		
		AB = new REG(1, "AB");
		AB.getOut(0).setIsInt();
		AB.getOut(0).setNumOfLines(8);
		
		BB = new REG(1, "BB");
		BB.getOut(0).setIsInt();
		BB.getOut(0).setNumOfLines(8);
		
		AW = new REG(1, "AW");
		AW.getOut(0).setIsInt();
		AW.getOut(0).setNumOfLines(16);
		
		BW = new REG(1, "BW");
		BW.getOut(0).setIsInt();
		BW.getOut(0).setNumOfLines(16);
		
		ALUExec = new ALU();
		
		ABout = new TSB();
		ABout.getOut(0).setNumOfLines(16);
		ALUout = new TSB();
		ALUout.getOut(0).setNumOfLines(8);
		BBout = new TSB();
		BBout.getOut(0).setNumOfLines(8);
		AWHout = new TSB();
		AWHout.getOut(0).setNumOfLines(8);
		AWout = new TSB();
		AWout.getOut(0).setNumOfLines(16);
		BWout = new TSB();
		BWout.getOut(0).setNumOfLines(16);
		
		
	}
	
	public static void connect() {
		
		////
		AB_zero_extend.setInputPin(0, AB.getOut(0));
		AW_H.setInputPin(0, AW.getOut(0));
		ABBits.setInputPin(0, AB.getOut(0));
		BBBits.setInputPin(0, BB.getOut(0));
		ALUBits.setInputPin(0, ALUExec.getOut(0));
		////
		
		CD1.setInputPin(0, Fetch2.ASR());
		CD1.setInputPin(1, Fetch2.LSR());
		CD1.setInputPin(2, Fetch2.ROR());
		CD1.setInputPin(3, Fetch2.RORC());
		
		CD2.setInputPin(0, Fetch2.ASL());
		CD2.setInputPin(1, Fetch2.LSL());
		CD2.setInputPin(2, Fetch2.ROL());
		CD2.setInputPin(3, Fetch2.ROLC());
		
		MX3.setCtrl(0, CD1.getOut(0));
		MX3.setCtrl(1, CD1.getOut(1));
		MX3.setInputPin(0, ABBits.getOut(7));
		MX3.setInputPin(1, new Pin(false));
		MX3.setInputPin(2, ABBits.getOut(0));
		MX3.setInputPin(3, Exec2.PSWC());
		
		MX4.setCtrl(0, CD2.getOut(0));
		MX4.setCtrl(1, CD2.getOut(1));
		MX4.setInputPin(0, new Pin(false));
		MX4.setInputPin(1, new Pin(false));
		MX4.setInputPin(2, ABBits.getOut(7));
		MX4.setInputPin(3, Exec2.PSWC());
		
		AB.setInputPin(0, Bus.IBUS_L());
		AB.setPinLd(UpravOper.ldAB());
		AB.setShr(UpravOper.shr());
		AB.setIR(MX3.getOut(0));
		AB.setShl(UpravOper.shl());
		AB.setIL(MX4.getOut(0));
			
		//AB.initVal(12);//////////////////////////////////// IZBACITI
		
		
		BB.setInputPin(0, Bus.IBUS_L());
		BB.setPinLd(UpravOper.ldBB());
		
		AW.setInputPin(0, Bus.IBUS());
		AW.setPinLd(UpravOper.ldAW());
		
		BW.setInputPin(0, Bus.IBUS());
		BW.setPinLd(UpravOper.ldBW());
		
		ALUExec.setPinX(AB.getOut(0));
		ALUExec.setPinY(BB.getOut(0));
		ALUExec.setPinAdd(UpravOper.add());
		ALUExec.setPinSub(UpravOper.sub());
		ALUExec.setPinAnd(UpravOper.and());
		ALUExec.setPinOr(UpravOper.or());
		ALUExec.setPinXor(UpravOper.xor());
		ALUExec.setPinNot(UpravOper.not());
		ALUExec.setPinInc(UpravOper.inc());
		ALUExec.setPinDec(UpravOper.dec());
		
		// TSB ABout, ALUout, BBout, AWHout, AWout, BWout;
		
		ABout.setInputPin(0, AB_zero_extend.getOut(0));
		ABout.setCtrl(UpravOper.ABout());
		Bus.addOnIBUS(ABout.getOut(0));
		
		ALUout.setInputPin(0, ALUExec.getOut(0));
		ALUout.setCtrl(UpravOper.ALUout());
		Bus.addOnIBUS(ALUout.getOut(0));
		
		BBout.setInputPin(0, BB.getOut(0));
		BBout.setCtrl(UpravOper.BBout());
		Bus.addOnIBUS(BBout.getOut(0));
		
		AWHout.setInputPin(0, AW_H.getOut(0));
		AWHout.setCtrl(UpravOper.AWHout());
		Bus.addOnIBUS(AWHout.getOut(0));
		
		AWout.setInputPin(0, AW.getOut(0));
		AWout.setCtrl(UpravOper.AWout());
		Bus.addOnIBUS(AWout.getOut(0));
		
		BWout.setInputPin(0, BW.getOut(0));
		BWout.setCtrl(UpravOper.BWout());
		Bus.addOnIBUS(BWout.getOut(0));
		
	}
	
	public static Pin AB0() {
		return ABBits.getOut(0);
	}

	public static Pin AB1() {
		return ABBits.getOut(1);
	}

	public static Pin AB2() {
		return ABBits.getOut(2);
	}

	public static Pin AB3() {
		return ABBits.getOut(3);
	}

	public static Pin AB4() {
		return ABBits.getOut(4);
	}

	public static Pin AB5() {
		return ABBits.getOut(5);
	}

	public static Pin AB6() {
		return ABBits.getOut(6);
	}

	public static Pin AB7() {
		return ABBits.getOut(7);
	}
	
	public static Pin C8() {
		return ALUExec.getPinC8();
	}
	
	public static Pin ALU7() {
		return ALUBits.getOut(7);
	}

	public static Pin BB7() {
		return BBBits.getOut(7);
	}
	
	//public static REG AB, BB, AW, BW;
	public static void ispisiRegistre() {
		System.out.println(" Registri:" + " AB=" + AB.getOut(0).getIntVal() + " BB=" + BB.getOut(0).getIntVal() +
							" AW=" + AW.getOut(0).getIntVal() + " BW=" + BW.getOut(0).getIntVal() );
	}
	
	public static void main(String[] args){
		
		Bus.init();
		Bus.connect();
		Fetch1.init();
		Fetch1.connect();
		Addr.init();
		Addr.connect();
		Exec1.init();
		
		Bus.addOnIBUS(new Pin(12,16));
		
		System.out.println( "IBUS_L " + Bus.IBUS_L().getIntVal() );
		
		LogicalComponent.CLK();
		
		AB.setInputPin(0, Bus.IBUS_L());
		AB.setPinLd(new Pin(true));
		
		BB.setInputPin(0, Bus.IBUS_L());
		BB.setPinLd(new Pin(true));
		
		AW.setInputPin(0, Bus.IBUS());
		AW.setPinLd(new Pin(true));
		
		AB_zero_extend.setInputPin(0, AB.getOut(0));
		AW_H.setInputPin(0, AW.getOut(0));
		
		ALUExec.setPinX(AB.getOut(0));
		ALUExec.setPinY(BB.getOut(0));
		ALUExec.setPinAdd(new Pin(false));
		ALUExec.setPinSub(new Pin(false));
		ALUExec.setPinAnd(new Pin(false));
		ALUExec.setPinOr(new Pin(false));
		ALUExec.setPinXor(new Pin(false));
		ALUExec.setPinNot(new Pin(false));
		ALUExec.setPinInc(new Pin(false));
		ALUExec.setPinDec(new Pin(false));

		LogicalComponent.CLK();
		
		System.out.println( "ALU " + Integer.toBinaryString(ALUExec.getOut(0).getIntVal()) );
		
		LogicalComponent.CLK();
		
		System.out.println( "AB " + AB.getOut(0).getIntVal() );
		System.out.println( "IBUS_L " + Bus.IBUS_L().getIntVal() );
		System.out.println( "AB_zero_ext " + AB_zero_extend.getOut(0).getIntVal() );
		System.out.println( "AW " + Integer.toBinaryString(AW.getOut(0).getIntVal()) );
		System.out.println( "AW_H " + Integer.toBinaryString(AW_H.getOut(0).getIntVal()) );
	}
	
}
